import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import { Link } from 'react-router-dom'
import {Button,Form,Input,Toast} from "antd-mobile"
import { reqlogin } from '../../http/api';
export default class Login extends Component {
    constructor(){
        super();
        this.state={
            user:{
                phone:"",
                password:"",
            },
        }
    }
async login(){
     let res = await reqlogin(this.state.user)
     if(res.data.code == 200){ //eslint-disable-line
        Toast.show({
            content:res.data.msg
        })
        //存信息
        sessionStorage.setItem("userInfo",JSON.stringify(res.data.list))
        //跳页面
        this.props.history.push("/index/home")
       }
}
  render() {
      let {user} = this.state
    return (
      <div>
          <Header register title="登陆"></Header>
          <div>user:{JSON.stringify(user)}</div>
          <Form layout='horizontal'>
          <Form.Item label='用户名' name='username'>
            <Input placeholder='请输入用户名' clearable  onChange={v=>{
               this.setState({
                   user:{
                       ...this.state.user,
                       phone:v
                   }
               })
            }}/>
          </Form.Item>
          <Form.Item label='密码' name='password'>
            <Input placeholder='请输入密码' clearable type='password' onChange={v=>{
                this.setState({
                    user:{
                        ...this.state.user,
                        password:v
                    }
                })
            }} />
          </Form.Item>
        </Form>
          <Button color='primary' size="mini" onClick={()=>this.login()}>登陆</Button>
          <Link to="/index/home">前往首页</Link>
      </div>
    )
  }
}